using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ExpertSMS.Models;

namespace ExpertSMS.Controllers
{   
    public class MakeFoodProductsController : Controller
    {
        private ExpertSMSContext context = new ExpertSMSContext();

        //
        // GET: /MakeFoodProducts/

        public ViewResult Index()
        {
            return View(context.MakeFoodProducts.Include(makefoodproduct => makefoodproduct.MakeFood).Include(makefoodproduct => makefoodproduct.Product).Include(makefoodproduct => makefoodproduct.Unit).ToList());
        }

        //
        // GET: /MakeFoodProducts/Details/5

        public ViewResult Details(int id)
        {
            MakeFoodProduct makefoodproduct = context.MakeFoodProducts.Single(x => x.MakeFoodProductID == id);
            return View(makefoodproduct);
        }

        //
        // GET: /MakeFoodProducts/Create

        public ActionResult Create()
        {
            ViewBag.PossibleMakeFoods = context.MakeFoods;
            ViewBag.PossibleProducts = context.Products;
            ViewBag.PossibleUnits = context.Units;
            return View();
        } 

        //
        // POST: /MakeFoodProducts/Create

        [HttpPost]
        public ActionResult Create(MakeFoodProduct makefoodproduct)
        {
            if (ModelState.IsValid)
            {
                context.MakeFoodProducts.Add(makefoodproduct);
                context.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.PossibleMakeFoods = context.MakeFoods;
            ViewBag.PossibleProducts = context.Products;
            ViewBag.PossibleUnits = context.Units;
            return View(makefoodproduct);
        }
        
        //
        // GET: /MakeFoodProducts/Edit/5
 
        public ActionResult Edit(int id)
        {
            MakeFoodProduct makefoodproduct = context.MakeFoodProducts.Single(x => x.MakeFoodProductID == id);
            ViewBag.PossibleMakeFoods = context.MakeFoods;
            ViewBag.PossibleProducts = context.Products;
            ViewBag.PossibleUnits = context.Units;
            return View(makefoodproduct);
        }

        //
        // POST: /MakeFoodProducts/Edit/5

        [HttpPost]
        public ActionResult Edit(MakeFoodProduct makefoodproduct)
        {
            if (ModelState.IsValid)
            {
                context.Entry(makefoodproduct).State = EntityState.Modified;
                context.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.PossibleMakeFoods = context.MakeFoods;
            ViewBag.PossibleProducts = context.Products;
            ViewBag.PossibleUnits = context.Units;
            return View(makefoodproduct);
        }

        //
        // GET: /MakeFoodProducts/Delete/5
 
        public ActionResult Delete(int id)
        {
            MakeFoodProduct makefoodproduct = context.MakeFoodProducts.Single(x => x.MakeFoodProductID == id);
            return View(makefoodproduct);
        }

        //
        // POST: /MakeFoodProducts/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            MakeFoodProduct makefoodproduct = context.MakeFoodProducts.Single(x => x.MakeFoodProductID == id);
            context.MakeFoodProducts.Remove(makefoodproduct);
            context.SaveChanges();
            return RedirectToAction("Index");
        }
    }
}